<template>
  <div>
    <div class="block">
      <span class="demonstration">时间范围</span>
      <el-date-picker
        v-model="searchObj.value"
        type="datetimerange"
        align="right"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        :default-time="['12:00:00', '08:00:00']"
      >
      </el-date-picker>
      <el-button type="primary" @click="query">查询</el-button>
    </div>
    <el-card class="box-card">
      <com-echarts :sendOption="sendObj"></com-echarts>
    </el-card>
  </div>
</template>

<script>
import { api_edit } from "../../api/order";
import moment from "moment";
import ComEcharts from "../../components/comEcharts";
export default {
  components: {
    ComEcharts,
  },
  data() {
    return {
      searchObj: {
        value: [],
        date: "",
      },
      sendObj: {
        title: "订单统计",
        legend: ["订单", "金额"],
        xAxis: [],
        series: [],
      },
    };
  },
  methods: {
    async query() {
      console.log(111);
      this.searchObj.date = JSON.stringify(this.searchObj.value);
      let rst = await api_edit(this.searchObj);
      let xAxis = [];
      let arr = [];
      rst.data.forEach((item, index) => {
        xAxis.push(moment(item.orderTime).format("YYYY-MM-DD"));
        arr.push(item.orderAmount);
      });
      this.sendObj.xAxis = xAxis;
      this.sendObj.series = [
        {
          name: "订单",
          type: "line",
          stack: "Total",
          areaStyle: {},
          emphasis: {
            focus: "series",
          },
          data: arr,
        },
      ];
      console.log(rst);
    },
  },
  mounted() {
    this.query();
  },
};
</script>

<style lang="less" scoped>
.con {
  display: flex;
  justify-content: space-between;
  text-align: center;
  .dindan {
    font-size: 50px;
    color: #0f95da;
  }
  .aa {
    color: red;
  }
  .cc {
    color: #1afa29;
  }
  ul > li:first-child {
    color: #ddd;
    margin-bottom: 5px;
  }
  ul > li:last-child {
    font-weight: 600;
  }
}
#main {
  min-width: 31.25rem;
  min-height: 31.25rem;
  // max-height: 500px;
}
#maychar {
  max-height: 500px;
  // max-height: 400px;
  height: 500px;
}
.box-card {
  margin-top: 20px;
}
</style>
